// 新增统计控制器
package cn.sightsnow.zh.controller;

import cn.sightsnow.zh.service.StatisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Api(tags = "医疗废物统计")
@RestController
@RequestMapping("/statistics")
@Slf4j
public class StatisticsController {

    private final StatisticsService statisticsService;

    public StatisticsController(StatisticsService statisticsService) {
        this.statisticsService = statisticsService;
    }

    @ApiOperation("获取指定日期范围内的每日医疗废物识别数量")
    @GetMapping("/daily-count")
    public Map<String, Integer> getDailyWasteCount(
            @ApiParam(value = "开始日期", example = "2024-02-07")
            @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate,
            @ApiParam(value = "结束日期", example = "2024-02-14")
            @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate
    ) {
        return statisticsService.getDailyWasteCount(startDate, endDate);
    }


    @ApiOperation("获取指定医疗废物的数量统计")
    @GetMapping("/waste-types")
    public Map<String, Long> getWasteTypeStatistics(
            @ApiParam(value = "开始日期", example = "2024-02-07")
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate,
            @ApiParam(value = "结束日期", example = "2024-02-14")
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate,
            @ApiParam(value = "物品类型列表，多个类型用逗号分隔", example = "手套,口罩,注射器")
            @RequestParam(required = false) String types
    ) {
        // 将逗号分隔的类型字符串转换为列表
        List<String> typeList = null;
        if (types != null && !types.isEmpty()) {
            typeList = Arrays.asList(types.split(","));
        }

        return statisticsService.getWasteTypeStatistics(startDate, endDate, typeList);
    }
}